home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13021 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: crl.crl.com!not-for-mail
  2. From: bobfry@crl.com (Robert Fry)
  3. Newsgroups: comp.unix.sco.programmer,comp.lang.c
  4. Subject: Re: Storing 20 character numbers
  5. Date: 3 Apr 1996 16:42:54 -0800
  6. Organization: CRL Dialup Internet Access
  7. Message-ID: <4jv5ue$6c8@crl.crl.com>
  8. References: <DpB3sz.J9n@idm.com>
  9. NNTP-Posting-Host: crl.com
  10.  
  11. eck@idm.com (Eric Kurbat) writes:
  12.  
  13. >    Anyway, the question is, how do you store a 20 character integer
  14. >number in a non-character variable in C without losing any of the digits?
  15. >I did a little bit of playing around and a long double loses precision after
  16. >about 16 digits. Does anyone have any ideas?
  17.  
  18. Gee, it works on my system when I just store it as a long! Seriously, the 
  19. exact maximum precision on any system is implementation defined. If you 
  20. want to store numbers with higher precision than that, you will need to 
  21. create your own data types to do the job. One fairly common (though far 
  22. from the most space-efficient) implementation is to store one or two 
  23. digits per byte, and do the carries, etc, whenever you do operations on 
  24. the numbers. This can be a lot of work if you need to implement efficient 
  25. math routines for various operations, but it's the only portable solution 
  26. I can think of.
  27.  
  28.   Bob
  29.